using System;
#if (!SILVERLIGHT)
using System.Collections;
#endif
using System.Collections.Generic;
using NUnit.Framework;


namespace ValidationFramework.Specifications.Tests
{
	public class HasNoDuplicatesSpecTests
	{

		const string expectedErrorMessage = "expectedErrorMessage";
		const string expectedRuleSet = "EXPECTEDRULESET";

		[TestFixture]
		public class Constructor1
		{
			[Test]
			public void Should_Default_Comparer_To_Null()
			{
				var validator = new ContainsNoDuplicatesSpec();
				Assert.IsNull(validator.Comparer);

			}
		}

		[TestFixture]
		public class Constructor2
		{
			[Test]
			public void Should_Save_Provided_Comparer()
			{
				var expectedComparer = StringComparer.Ordinal;
				var validator = new ContainsNoDuplicatesSpec(expectedComparer);

				Assert.AreEqual(validator.Comparer, expectedComparer);

			}
		}

		[TestFixture]
		public class Validate
		{
			[Test]
			public void Generic()
			{
				var validator = new ContainsNoDuplicatesSpec();
				List<int> list = null;
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list = new List<int>();
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list.Add(1);
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list.Add(1);
				Assert.IsFalse(validator.IsSatisfiedBy(list));
			}
#if(!SILVERLIGHT)
			[Test]
			public void NonGeneric()
			{

				var validator = new ContainsNoDuplicatesSpec();
				ArrayList list = null;
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list = new ArrayList();
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list.Add(1);
				Assert.IsTrue(validator.IsSatisfiedBy(list));

				list.Add(1);
				Assert.IsFalse(validator.IsSatisfiedBy(list));

			}
#endif
		}

		[TestFixture]
		public class IsEquivalentTo
		{
			[Test]
			public void Equality()
			{
				var validator1 = new ContainsNoDuplicatesSpec();
				var validator2 = new ContainsNoDuplicatesSpec();

				Assert.IsTrue(validator1.IsEquivalentTo(validator2));

			}
			[Test]
			public void Equality2()
			{
				var validator1 = new ContainsNoDuplicatesSpec(StringComparer.Ordinal);
				var validator2 = new ContainsNoDuplicatesSpec(StringComparer.Ordinal);

				Assert.IsTrue(validator1.IsEquivalentTo(validator2));

			}
			[Test]
			public void Equality3()
			{
				var validator1 = new ContainsNoDuplicatesSpec(StringComparer.Ordinal);
				var validator2 = new ContainsNoDuplicatesSpec();

				Assert.IsFalse(validator1.IsEquivalentTo(validator2));
			}
		}

		[TestFixture]
		public class CheckTypes
		{
			[Test]
			public void Should_Be_Able_Validate_The_Following_Types()
			{
				var validator = new ContainsNoDuplicatesSpec();
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(IList<int>)));
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(List<int>)));
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(ICollection<int>)));
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(LinkedList<int>)));
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(Stack<int>)));
#if (!SILVERLIGHT)
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(ArrayList)));
#endif
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(string)));
				Assert.IsTrue(validator.CanBeSatisfiedBy(typeof(int[])));
			}
			[Test]
			public void Should_Not_Be_Able_To_Validate_The_Following_Types()
			{
				var validator = new ContainsNoDuplicatesSpec();
				Assert.IsFalse(validator.CanBeSatisfiedBy(typeof(int)));
			}
		}

	}
}